let baseURL = "http://123.56.105.243:8080"
const TOKEN = wx.getStorageSync('token')
export let http = (url,method = "GET",data = {}) => {
  return new Promise((resolve,reject)=>{
    wx.request({
      url:baseURL+url,
      method,
      data,
      timeout:5000,
      header:{
        "contentType": "application/json;charset=UTF-8",
        "token":TOKEN
      },
      complete:(xhr)=>{
        if(xhr.statusCode == 401){
          let curRoute = getCurrentPages()[0].route
          console.log(curRoute);
          wx.redirectTo({
            url: curRoute,
          })
        }
      },
      success:res=>{
        if(res.statusCode == 200){
          resolve(res.data)
        }
        wx.hideLoading()
      },
      fail:err=>{
        reject(err)
      }
    })
  })
}
